package com.fengjue.userservice.controller;

import com.fengjue.userservice.entity.Product;
import com.fengjue.userservice.feignclient.ProductClient;
import com.sun.org.apache.regexp.internal.RE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.net.URI;
import java.util.List;
import java.util.Map;

@RestController
public class UserController {

    @Autowired
    private DiscoveryClient discoveryClient;

    @Autowired
   private LoadBalancerClient loadBalancerClient;

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private ProductClient productClient;


    @GetMapping("/user/showProduct")
    public String showProduct(){
//        String url="http://productservice/product/showMsg";
//        String forObject = restTemplate.getForObject(url, String.class);
        String forObject = productClient.showMsg();
        return forObject;
    }
    @GetMapping("/user/feign1")
    public Map<String,Object> test1(String id){
        Map<String, Object> msg = productClient.findOne(id);
        return msg;
    }
    @GetMapping("/user/feign2")
    public Map<String,Object> test1(Product product){

        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("product = " + product);
        Map<String, Object> msg = productClient.update(product);
        return msg;
    }

}
